package com.xhcl.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xhcl.common.core.domain.Stree;
import com.xhcl.common.core.text.Convert;
import com.xhcl.common.utils.StringUtils;
import com.xhcl.system.domain.TGgFsdwxm;
import com.xhcl.system.domain.TGgPtdwgj;
import com.xhcl.system.domain.TGgXmxx;
import com.xhcl.system.mapper.TGgFsdwxmMapper;
import com.xhcl.system.mapper.TGgXmxxMapper;
import com.xhcl.system.service.ITGgXmxxService;

/**
 * 项目信息Service业务层处理
 * 
 * @author xhcl
 * @date 2020-11-01
 */
@Service
public class TGgXmxxServiceImpl implements ITGgXmxxService 
{
    @Autowired
    private TGgXmxxMapper tGgXmxxMapper;
    
    @Autowired
    private TGgFsdwxmMapper tGgFsdwxmMapper;

    /**
     * 查询项目信息
     * 
     * @param xmbm 项目信息ID
     * @return 项目信息
     */
    @Override
    public TGgXmxx selectTGgXmxxById(String xmbm)
    {
        return tGgXmxxMapper.selectTGgXmxxById(xmbm);
    }

    /**
     * 查询项目信息列表
     * 
     * @param tGgXmxx 项目信息
     * @return 项目信息
     */
    @Override
    public List<TGgXmxx> selectTGgXmxxList(TGgXmxx tGgXmxx)
    {
        return tGgXmxxMapper.selectTGgXmxxList(tGgXmxx);
    }

    /**
     * 新增项目信息
     * 
     * @param tGgXmxx 项目信息
     * @return 结果
     */
    @Override
    public int insertTGgXmxx(TGgXmxx tGgXmxx)
    {
        return tGgXmxxMapper.insertTGgXmxx(tGgXmxx);
    }

    /**
     * 修改项目信息
     * 
     * @param tGgXmxx 项目信息
     * @return 结果
     */
    @Override
    public int updateTGgXmxx(TGgXmxx tGgXmxx)
    {
        return tGgXmxxMapper.updateTGgXmxx(tGgXmxx);
    }

    /**
     * 删除项目信息对象
     * 
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteTGgXmxxByIds(String ids)
    {
        return tGgXmxxMapper.deleteTGgXmxxByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除项目信息信息
     * 
     * @param xmbm 项目信息ID
     * @return 结果
     */
    @Override
    public int deleteTGgXmxxById(String xmbm)
    {
        return tGgXmxxMapper.deleteTGgXmxxById(xmbm);
    }

    /**
     * 查询项目信息树列表
     * 
     * @return 所有项目信息信息
     */
    @Override
    public List<Stree> selectTGgXmxxTree(String dwbm)
    {   
    	TGgXmxx ggXmxx=new TGgXmxx();
    	if (StringUtils.isNotEmpty(dwbm)){
    		ggXmxx.getParams().put("dwbm", dwbm);
    	}
        List<TGgXmxx> tGgXmxxList = tGgXmxxMapper.selectTGgXmxxList(ggXmxx);
        List<Stree> ztrees = new ArrayList<Stree>();
        for (TGgXmxx tGgXmxx : tGgXmxxList)
        {
        	Stree ztree = new Stree();
            ztree.setId(tGgXmxx.getXmbm());
            ztree.setpId(tGgXmxx.getSjxmbm());
            ztree.setName(tGgXmxx.getXmbm()+"-"+tGgXmxx.getXmmc());
            ztree.setTitle(tGgXmxx.getXmmc()+"^"+tGgXmxx.getYskmbm()+"^"+tGgXmxx.getYskmmc());
            ztrees.add(ztree);
        }
        return ztrees;
    }
    
    
    
    public List<Stree> selectfsdwmGjXmxxTree(String dwbm)
    {   
    	List<TGgFsdwxm> list=null;
    	if (StringUtils.isNotEmpty(dwbm)) {
    		TGgFsdwxm tGgFsdwxm=new TGgFsdwxm();
    		tGgFsdwxm.setDwbm(dwbm);
    		list=tGgFsdwxmMapper.selectTGgFsdwxmList(tGgFsdwxm);
    	}
	    List<TGgXmxx> tGgXmxxList = tGgXmxxMapper.selectTGgXmxxList(new TGgXmxx());
        List<Stree> ztrees = new ArrayList<Stree>();
        for (TGgXmxx tGgXmxx : tGgXmxxList)
        {
        	Stree ztree = new Stree();
            ztree.setId(tGgXmxx.getXmbm());
            ztree.setpId(tGgXmxx.getSjxmbm());
            ztree.setName(tGgXmxx.getXmbm()+"-"+tGgXmxx.getXmmc());
            ztree.setTitle(tGgXmxx.getXmmc());
            if (list!=null) {
	        	ztree.setChecked(list.stream().filter(m->m.getXmbm().equals(tGgXmxx.getXmbm())).count()>0);
	        }
            ztrees.add(ztree);
        }
        return ztrees;
    }
}
